﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Presenter;

namespace QLHV_MVP
{
    public partial class frmStudent : Form, IStudentView

    {
        private Student _presenter;
        public frmStudent()
        {
            InitializeComponent();
            grdHocvien.ReadOnly = true;
            _presenter = new Student(this);
            _presenter.BindingdataForGridView();
            
           
        }
        #region IStudentView Members

        public string Mahv
        {
            get { return Mahv; }
            set { Mahv = value; }
        }
        public string HoDem
        {
            get { return HoDem; }
            set { HoDem = value; }
        }
        public string Ten
        {
            get { return Ten; }
            set { Ten = value; }
        }
        public DateTime? Ngaysinh
        {
            get { return Ngaysinh; }
            set { Ngaysinh = value; }
        }
        public Boolean Gioitinh
        {
            get { return Gioitinh; }
            set { Gioitinh = value; }
        }
        public string Diachi
        {
            get { return Diachi; }
            set { Diachi = value; }
        }
        void IStudentView.GridBinding(DataTable data)
        {
            grdHocvien.DataSource = data;
        }
        void IStudentView.dete(DataTable data)
        {
            grdHocvien.Rows.Remove(grdHocvien.CurrentRow);
            grdHocvien.DataSource = data;
        }
        void IStudentView.add(DataTable data)
        {
            DataRow dr = data.NewRow();
            data.Rows.Add(dr);
            grdHocvien.DataSource = data;
        }
        void IStudentView.returnData(DataTable data)
        {
           
            grdHocvien.DataSource = data;  
        }
       
        #endregion

       
        private void btnThem_Click(object sender, EventArgs e)
        {
            _presenter.addData();
            grdHocvien.ReadOnly = false;
            btnThem.Enabled = btnSua.Enabled = btnXoa.Enabled = false;
            btnLuu.Enabled = btnBoqua.Enabled = true;
        }

        private void btnBoqua_Click(object sender, EventArgs e)
        {
            _presenter.returnDataStudent();
            grdHocvien.ReadOnly = true;
            btnBoqua.Enabled = btnLuu.Enabled = false;
            btnThem.Enabled = btnSua.Enabled = btnXoa.Enabled = true;
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            _presenter.Update();
            grdHocvien.ReadOnly = true;
            btnThem.Enabled = btnSua.Enabled = btnXoa.Enabled = true;
            btnLuu.Enabled = btnBoqua.Enabled = false;
        }

        private void btnNLCS_Click(object sender, EventArgs e)
        {
            _presenter.BindingdataForGridView();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            grdHocvien.ReadOnly = false;
            btnBoqua.Enabled = btnLuu.Enabled = true;
            btnThem.Enabled = btnSua.Enabled = btnXoa.Enabled = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("Thoát chương trình", "Quản lý lớp học", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (DialogResult == DialogResult.Yes)
            {
                this.Close();
            }

        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            _presenter.delete();
            btnThem.Enabled = btnSua.Enabled = false;
            btnXoa.Enabled = btnBoqua.Enabled = btnLuu.Enabled = true;
        }
     
    }
}
